// Copyright (c) 2021 Presto Labs Pte. Ltd.
// Author: fengyang

#pragma once

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "coin2/exchange/base/symbology/spot_product.h"
#include "coin2/exchange/base/symbology/util.h"
#include "coin2/exchange/upbit_sg/symbology/currency.h"
#include "coin2/exchange/upbit/symbology/product_util.h"

namespace coin2::exchange::upbit_sg::symbology {

using namespace coin2::exchange::upbit::symbology::util;

class UpbitSgProduct
    : public base::symbology::SpotProduct<UpbitSgCurrency, UpbitSgProduct>,
      public base::symbology::ProductFromStrMixin<UpbitSgProduct> {
 public:
  typedef SpotProduct<UpbitSgCurrency, UpbitSgProduct> BaseProduct;

  UpbitSgProduct(
      const UpbitSgCurrency& base,
      const UpbitSgCurrency& quote) :
    SpotProduct(
        base,
        quote,
        ToUpbitNativeProduct(base, quote),
        ToUpbitNativeProduct(base, quote),
        base::market::ExchangeType::Upbitsg) { }

 public:
  static std::unique_ptr<UpbitSgProduct> FromNativeStrImpl(
      const std::string& native_product,
      int64_t resolve_timestamp) {
    std::unique_ptr<UpbitSgCurrency> base_ptr;
    std::unique_ptr<UpbitSgCurrency> quote_ptr;
    bool success = ParseUpbitNativeProduct(
        native_product, resolve_timestamp, &base_ptr, &quote_ptr);
    if (success) {
      return std::make_unique<UpbitSgProduct>(*base_ptr, *quote_ptr);
    } else {
      return { };
    }
  }
};

}  // namespace coin2::exchange::upbit_sg::symbology
